<layout name='Layout/ace_popup' />
<script type="text/javascript">
	function save() {
		$("#dept_wrap", parent.document).hide();
		$("#dept_wrap span.address_list", parent.document).html("");

		$("#rc select option").each(function(i) {
			id = $(this).val();
			name = jQuery.trim($(this).text());
			html = conv_inputbox_item(id, name, name, id);
			$("#dept_wrap .address_list", parent.document).append(html);
		});

		$("#dept_wrap", parent.document).show();

		myclose();
	}


	$(document).ready(function() {
		$("#dept .tree_menu  a").click(function() {
			$("#dept .tree_menu a").removeClass("active");
			$(this).addClass("active");
			return false;
			//禁止连接生效
		});

		$("#dept .tree_menu  a").dblclick(function() {
			$("#dept .tree_menu a").removeClass("active");
			$(this).addClass("active");
			add_address('rc');
			return false;
			//禁止连接生效
		});

		$("#rc  select").on("dblclick", function() {
			$(this).find("option:selected").remove();
			$("#rc_count").text("(" + $("#rc select option").length + ")");
		});

		$("#rc select").droppable({
			activeClass : "ui-state-default",
			hoverClass : "ui-state-hover",
			accept : ":not(.ui-sortable-helper)",
			drop : function(event, ui) {
				$text = ui.draggable.text();
				$val = ui.draggable.find("input").val();
				if ($("#rc select option[value='" + $val + "']").val() == undefined) {
					$("<option></option>").val($val).text($text).appendTo(this);
					$("#rc_count").text("(" + $("#rc select option").length + ")");
				};
			},
		}).sortable({
			items : "option:not(.placeholder)",
			sort : function() {
				// gets added unintentionally by droppable interacting with sortable
				// using connectWithSortable fixes this, but doesn't allow you to customize active/hoverClass options
				$(this).removeClass("ui-state-default");
			}
		});

	})
	//最终确认

	function add_address(name) {
		$dept_id = $("#dept a.active").attr("node");
		$dept_name = $("#dept a.active span").text();

		if ($dept_id == undefined) {
			ui_error("请选择部门");
			return false;
		}
		$text = $dept_name;
		$val = "dept_" + $dept_id;
		if ($("#" + name + " select option[value='" + $val + "']").val() == undefined) {
			$("<option></option>").val($val).text($text).appendTo("#" + name + " select");
			$("#" + name + "_count").text("(" + $("#" + name + " select option").length + ")");
		};
	}

	//-->
</script>
<div class="panel panel-default ">
	<div class="panel-heading clearfix">
		<div class="pull-left">
			<h4>选择部门</h4>双击可以添加和删除对应的节点
		</div>
		<div class="pull-right">
			<a  onclick="save();" class="btn btn-sm btn-primary">确定</a>
			<a  onclick="myclose();" class="btn btn-sm btn-primary">关闭</a>
		</div>
	</div>
	<div class="panel-body">
		<div class="col-28 pull-left">
			<div class="">
				<b>部门</b>
			</div>
			<div class="popup_tree_menu" >
				<div id="dept" style="width:100%;height:424px;" class="dp dept">
					{$list_dept}
				</div>
			</div>
		</div>
		<div class="col-34 pull-right">
			<div>
				<b style="padding-left: 60px;">已选</b><span id="rc_count"></span>
			</div>
			<div class="clearfix" style="margin-bottom: 15px;">
				<label class="col-4 pull-left text-right" ><a onclick="add_address('rc');" class="btn btn-sm btn-primary"> <i class="fa fa-angle-double-right"></i> </a> </label>
				<div class="col-28 pull-right">
					<div id="rc" style="width:100%;height:424px;overflow:hidden">
						<select size="6" style="height:100%;width:100%;"></select>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>